local kl__xiongsi = fk.CreateSkill {
  name = "kl__xiongsi",
  tags = { Skill.Limited },
}


kl__xiongsi:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  max_target_num = 0,
  prompt = "#kl__xiongsi",
  can_use = function(self, player)
    if player:usedSkillTimes(kl__xiongsi.name, Player.HistoryGame) == 0 then
      return (#player:getCardIds("h") > 0 and table.find(player:getCardIds("h"), function(id) return not player:prohibitDiscard(id) end))
      or (#player:getCardIds("e") > 0 and table.find(player:getCardIds("e"), function(id) return not player:prohibitDiscard(id) end))
      or (#player:getCardIds("e") > 0 and table.find(player:getCardIds("j"), function(id) return not player:prohibitDiscard(id) end))
    end
  end,
  interaction = function(self, player)
    local all_choices = {"kl__xiongsi-hand", "kl__xiongsi-equip","kl__xiongsi-judge"}
    local choices = {}
    if #player:getCardIds("h") > 0 and table.find(player:getCardIds("h"), function(id) return not player:prohibitDiscard(id) end) then
      table.insert(choices, "kl__xiongsi-hand")
    end
    if #player:getCardIds("e") > 0 and table.find(player:getCardIds("e"), function(id) return not player:prohibitDiscard(id) end) then
      table.insert(choices, "kl__xiongsi-equip")
    end
    if #player:getCardIds("j") > 0 and table.find(player:getCardIds("j"), function(id) return not player:prohibitDiscard(id) end) then
      table.insert(choices, "kl__xiongsi-judge")
    end
    return UI.ComboBox { choices = choices, all_choices = all_choices }
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    if self.interaction.data == "kl__xiongsi-hand" then
      player:throwAllCards("hand")
    elseif self.interaction.data == "kl__xiongsi-equip" then
      player:throwAllCards("equip")
    elseif self.interaction.data == "kl__xiongsi-judge" then
      player:throwAllCards("judge")
    end
    room:damage{
      from = nil,
      to = player,
      damage = 1,
      skillName = kl__xiongsi.name,
    }
    local chosen = room:askToChoice(player, {
      choices = {"kl__xiongsi_all", "kl__xiongsi_one"},
      skill_name = kl__xiongsi.name,
      cancelable = false,
    })
    if chosen == "kl__xiongsi_all" then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        room:loseHp(p, 1, kl__xiongsi.name)
      end
    else
      local to = room:askToChoosePlayers(player, {
        max_num = 1,
        min_num = 1,
        targets = room:getOtherPlayers(player),
        skill_name = kl__xiongsi.name,
        cancelable = false,
      })
      room:loseHp(to[1], 2, kl__xiongsi.name)
    end
  end,
})

return kl__xiongsi
